<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script src="{{ getAssets }}lodop/LodopFuncs.js?v={{ assets_version }}"></script>
<script>
var dataTablesDoctorOrder = $('#dataTablesDoctorOrder').DataTable({
    order:[]
    ,columns: [
        {"bSortable": false, render:function(data, type, full, meta) {
                return full.id;
        }}
        ,{"mDataProp" : "doctororder.status", "bSortable": false, "render":function (data, type, full, meta) {
                var xu = '';
                var pay = '';
                switch (parseInt(full.doctororder.pay_status)) {
                    case 0:pay ='未支付';break;
                    case 1:pay ='已支付';break;
                    case 2:pay ='待退费';break;
                    case 3:pay ='已退费';break;
                }
                switch (parseInt(data)) {
                    case 0:xu ='<span>待发送</span> ';break;
                    case 1:xu ='<span class="am-text-secondary">已发送('+ pay +')</span> ';break;
                    case 2:xu ='<span class="am-text-warning">已回退('+ pay +')</span> ';break;
                    case 3:xu ='<span class="am-text-danger">已退费('+ pay +')</span>';break;
                    case 4:xu ='<span style="color: gray">已作废('+ pay +')</span>';break;
                }
                return '<span class="number" style="white-space:nowrap;" data-index="'+ meta.row +'" data-number="'+ full.doctororder.number.id +'" data-prescdate="'+ timetransDate(full.doctororder.number.created_at) +'">'+xu+'</span><input type="hidden" class="project_type" value="'+ full.doctororder.project_type +'"><input type="hidden" class="total_price" value="'+ full.doctororder.total_price +'">';
            }},
        {"mDataProp" : "doctororder.number.id","bSortable": false, "render":function (data, type, full, meta) {
                return '<span >'+ full.doctororder.content_number +'</span>';
            }},
        {"mDataProp" : "doctororder.content", "bSortable": false, "render":function (data, type, full, meta) {
                return '<span class="content">'+ data +'</span>';
            }},
        {"mDataProp" : "doctororder.dosage_zl", "bSortable": false,"render":function (data, type, full, meta) {
                return '<span class="dosage_zl">'+ data +'</span>';
            }},
        {"mDataProp" : "doctororder.unit", "bSortable": false,"render":function (data, type, full, meta) {
                return '<span class="unit">'+ data +'</span>';
            }},
        {"bSortable": false, render:function(data, type, full, meta) {
                return full.doctororder.unit_price;
            }},
        {"bSortable": false, render:function(data, type, full, meta) {
                return full.total_money;
            }},
        {"mDataProp" : "doctororder.doctor_name", "bSortable": false,"render":function (data, type, full, meta) {
                return '<span class="doctor_name">'+ data +'</span>';
            }},
        {"mDataProp" : "created_at", "bSortable": false,"render":function (data, type, full, meta) {
                return '<span class="created_at">'+ timetrans(data) +'</span>';
            }},
    ]
    ,'bLengthChange': false
    ,"serverSide": false
    ,"bPaginate" : false
    ,"bFilter" : false
    ,"bInfo" : false
    ,"bProcessing" : false
    ,"drawCallback": function ( settings ) {

    }
});
//查询处方列表
var sel_detail_info;
function doctorOrderQuery() {
    $.post('{{urlfor "CollectfeesController.LogsDetail"}}',{'id':getQueryVariable('id')}, function(res){
        if(res.code == 1) {
            return false;
        }
        var dt = $('#dataTablesDoctorOrder').DataTable();
        dt.clear().draw();
        $.each(res.data.doctor_order, function (index, value) {
            dt.row.add(value).draw();
        });
        sel_detail_info = res.data;
    }, 'json');
}
doctorOrderQuery();
//打印

$('#viewDetailPrints').click(function () {
    if(!sel_detail_info) {
        layer.msg('没有可打印数据');
        return false;
    }

    var style = "<style>\
		.print_template{ font-size: 12px; padding: 10px;}\
		.w100{width: 100%;}\
		.print_template .h1{ font-size:18px; text-align:center; font-weight:400; padding:0; margin:20px 0;}\
		.tables{ border:1px solid #000;border-width:1px 0 0 1px; border-collapse:collapse;}\
		.tables thead td{border:1px solid #000;border-width:0 1px 1px 0; padding:2px; text-align:center; color:#333; line-height: 1.3; font-size: 10px;}\
		.tables tbody td{border:1px solid #000;border-width:0 1px 1px 0; padding:2px; text-align:center; color:#333; line-height: 1.3; font-size: 10px;}\
		</style>";
    var html = [];
    if(sel_detail_info.doctor_order) {
        html.push('<div class="print_template"> <h1 class="h1">'+ WG.fullname +'收费票据</h1><table class="w100"><tr><td width="30%">姓名：'+ sel_detail_info.archives.Realname +'</td><td width="30%">性别：'+ sel_detail_info.archives.Sex +'</td><td>票据号：'+ sel_detail_info.number +'</td></tr>');
        html.push('<tr><td>病人类别：自费</td><td>费别：自费</td><td>处方号：</td></tr></table>');
        html.push('<table  class="tables w100"><thead><tr><td>编码</td><td>明细名称</td><td>规格</td><td>单价</td><td>数量</td><td>单位</td><td>金额</td><td>全额</td></tr></thead><tbody>');
        $.each(sel_detail_info.doctor_order,function (idx, va) {
            val = va.doctororder;
            if(val.pay_status == 1) {
                var ch = [];
                ch.push('<tr>');
                ch.push('<td>'+ val.content_number +'</td>');
                ch.push('<td>'+ val.content +'</td>');
                ch.push('<td>'+ val.content_spec +'</td>');
                ch.push('<td>'+ val.unit_price +'</td><td>'+ val.dosage_zl +'</td><td>'+ val.unit +'</td><td>'+ va.total_money +'</td><td>'+ va.total_money +'</td>');
                ch.push('</tr>');
                html.push(ch.join(''));
            }
        });
        html.push('</tbody></table><table class="w100"><tr><td width="50%">结帐时间：'+ timetrans(sel_detail_info.created_at) +'</td><td style="text-align: right;">收费员：'+ sel_detail_info.created_by +'</td></tr></table></div>');
    }
    LODOP=getLodop();
    LODOP.SET_PRINT_PAGESIZE(0,"210mm","148mm","A5");
    LODOP.SET_PRINT_MODE("POS_BASEON_PAPER",true);
    LODOP.ADD_PRINT_HTM(20,25,'100%', '100%',style+html.join(''));
    LODOP.PREVIEW();
    return false;
});

</script>
